<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Visual rendering</title>
  <style>
    .imgs {
      --imgWidth: 200px;
      --imgHeight: 300px;
      display: flex;
      flex-direction: column;
    }

    .imgs img {
      width: var(--imgWidth);
      height: var(--imgHeight);
    }
  </style>
</head>

<body>
  <div class="imgs">
  </div>
  <script>
    window.onload = function () {
      window.addEventListener('scroll', watchScrollDown)
    }
    const imgsList = ['https://picsum.photos/id/237/200/300', 'https://picsum.photos/id/238/200/300', 'https://picsum.photos/id/239/200/300', 'https://picsum.photos/id/240/200/300', 'https://picsum.photos/id/241/200/300', 'https://picsum.photos/id/242/200/300', 'https://picsum.photos/id/243/200/300', 'https://picsum.photos/id/244/200/300']
    const imgsDiv = document.querySelector('.imgs')
    const computedStyles = getComputedStyle(imgsDiv);
    let imgWidth = computedStyles
      .getPropertyValue("--imgWidth")
      .trim();
    let imgHeight = computedStyles
      .getPropertyValue("--imgHeight")
      .trim();
    imgHeight = Number(imgHeight.slice(0, -2))
    let clientWidth = document.documentElement.clientWidth
    let clientHeight = document.documentElement.clientHeight
    let imgMaxCount = Math.floor(clientHeight / imgHeight) + 1
    for (let i = 0; i < imgMaxCount; i++) {
      let img = document.createElement('img')
      img.src = imgsList[i]
      imgsDiv.appendChild(img)
    }
    function watchScrollDown() {
      let scrollTop = document.documentElement.scrollTop || document.body.scrollTop
      // console.log(imgHeight * imgMaxCount - clientHeight)
      if (scrollTop >= imgHeight * imgMaxCount - clientHeight) {
        let index = imgMaxCount++
        if (index >= imgsList.length) {
          window.removeEventListener('scroll', watchScrollDown)
          return
        }
        let img = document.createElement('img')
        img.src = imgsList[index]
        imgsDiv.appendChild(img)
      }
    }
  </script>
</body>

</html>